package com.lj.mcore.entity;

import com.lj.mcore.domain.IdEntity;
import jakarta.persistence.*;
import org.hibernate.annotations.UpdateTimestamp;

import java.util.Date;

/**
 * 促销表
 * 主要存储商户的促销信息
 */
@Entity
@Table(name="shopping_promo")
public class Promo extends IdEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    Store store;

    /**
     * 1 代表作用系统内所有商品
     * 0 代表默认，商家自己的促销
     */
    @Column(columnDefinition="int default 0")
    private int scope;

    /**
     * 开始时间
     */
    private Date startTime;


    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 1 启用
     * 0 未启用，
     * -1 已过期，已失效，已关闭
     */
    @Column(columnDefinition="int default 1")
    int status;

    /**
     * 0 满减 ：满200减30，满500减90 满800减200
     * 1 满折：2件打八折，3件5折
     * 3 特价：打八折
     * 互斥关系，想同启用时间内，按最近的新建时间生效，只采用一个促销规则。防止成本击穿
     */
    @Column(columnDefinition="int default 0")
    private int type;

    /**
     * 当scope = 1时；生效
     *  scopeType = 0 促销规则作用于商品类别，制定storeclass
     *  scopeType = 1 促销规则作用于单品，指定goods
     */
    @Column(columnDefinition="int default 0")
    private int scopeType;


    /**
     * 当type=0时，[{over：200,minus：300},{over：500,minus：90},{over：800,minus：200}]
     * 当type=1时，[{buyCount：2,rate：8},{over：3,rate：5}]
     * 当type=2时，{rate:8}
     */
    @Lob
    @Column(columnDefinition="LongText")
    String rules;

    @UpdateTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;


    /**
     * 限购 每人限购多少个商品
     * 0：不限购
     */
    @Column(columnDefinition="int default 0")
    int quota;

    @OneToOne(fetch = FetchType.LAZY,mappedBy = "promo")
    Goods goods;

    @OneToOne(fetch = FetchType.LAZY,mappedBy = "promo")
    GoodsClass goodsClass;

    @OneToOne(fetch = FetchType.LAZY,mappedBy = "promo")
    StoreClass storeClass;


    public Store getStore() {
        return store;
    }

    public void setStore(Store store) {
        this.store = store;
    }

    public StoreClass getStoreClass() {
        return storeClass;
    }

    public void setStoreClass(StoreClass storeClass) {
        this.storeClass = storeClass;
    }

    public int getScopeType() {
        return scopeType;
    }

    public void setScopeType(int scopeType) {
        this.scopeType = scopeType;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public int getScope() {
        return scope;
    }

    public void setScope(int scope) {
        this.scope = scope;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getRules() {
        return rules;
    }

    public void setRules(String rules) {
        this.rules = rules;
    }

    public int getQuota() {
        return quota;
    }

    public void setQuota(int quota) {
        this.quota = quota;
    }

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public GoodsClass getGoodsClass() {
        return goodsClass;
    }

    public void setGoodsClass(GoodsClass goodsClass) {
        this.goodsClass = goodsClass;
    }
}
